/** 
 * @页面常用方法
 * @author XXZ 
 * @version 1.0.0  
 */

/************************** 提示信息框  *********************
 * 依赖js-lib：jquery.js、jquery-lhgdialog
 * */
// 警告信息框
function alertBox(id,info,islocked){
	var dlg = $.dialog({
			id:id,
			lock:islocked,
		 	title:"提示",
		 	min:false,max:false,
		    icon: 'hits.png',
		    content: info
	 });
	 $("#bg-frame").remove();
	 dlg.DOM.inner.append('<iframe id="bg-frame" class="bg-frame" frameborder="0" src="about:blank"></iframe>');
	 dlg.DOM.close.blur();
	 return dlg;
}
//删除提示框
function deleteBox(content,sureCall){
	var dlg = $.dialog({
			id:"isdelete",
			lock:false,
		 	title:"提示",
		 	min:false,max:false,
		    icon: 'hits.png',
		    content: content,
		    button:[{
		    	name:'确认',callback:sureCall
		    },{
		    	name:'取消',callback:function(){
		    		
		    	}
		    }]
	 });
	 $("#bg-frame").remove();
	 dlg.DOM.inner.append('<iframe id="bg-frame" class="bg-frame" frameborder="0" src="about:blank"></iframe>');
	 dlg.DOM.close.blur();
	 return dlg;
}
// 成功信息框
function successBox(id,info,islocked){
	var dlg= $.dialog({
			id:id,
			lock:(typeof islocked=="undefined"||islocked==null?false:true),
		 	title:Message.OKTitle,
		 	min:false,max:false,
		    icon: 'succ.png',
		    content: info
	 });
	 $("#bg-frame").remove();
	 dlg.DOM.inner.append('<iframe id="bg-frame" class="bg-frame" frameborder="0" src="about:blank"></iframe>');
	 dlg.DOM.close.blur();
	 return dlg;
}
// 失败信息框
function failBox(id,info,islocked){
	var dlg= $.dialog({
			id:id,
			lock:(typeof islocked=="undefined"||islocked==null?false:true),
		 	title:Message.FailTitle,
		 	min:false,max:false,
		    icon: 'face-sad.png',
		    content: info
	 });
	$("#bg-frame").remove();
	dlg.DOM.inner.append('<iframe id="bg-frame" class="bg-frame" frameborder="0" src="about:blank"></iframe>');
	dlg.DOM.close.blur();
	 return dlg;
}
//失败信息框 2
function failBox2(id,info,islocked){
	var dlg= $.dialog({
			id:id,
			lock:(typeof islocked=="undefined"||islocked==null?false:true),
		 	title:Message.FailTitle,
		 	min:false,max:false,
		    icon: 'face-sad.png',
		    content: info
	 });
	$("#bg-frame").remove();
	dlg.DOM.inner.append('<iframe id="bg-frame" class="bg-frame" frameborder="0" src="about:blank"></iframe>');
	dlg.DOM.close.blur();
	 return dlg;
}
// 服务端错误
function serverError(msg){
	msg = msg || Message.ServerError;
	if(debugMode) $.dialog.tips(msg);
}
/************************** 处理过程等待信息框  *********************
 * 自动关闭
 * 依赖js-lib：jquery.js、jquery-lhgdialog
 * */
// 开始处理后等待信息框
function processBegin(info){
	if(typeof info=="undefined" || info==null) info = Message.DataLoading;
	var dlg = $.dialog.tips(info,1000,'loading.gif',function(){ });
	dlg.DOM.wrap.css("top","40%");
	$("#bg-frame").remove();
	dlg.DOM.inner.append('<iframe id="bg-frame" class="bg-frame" frameborder="0" src="about:blank"></iframe>');
}
function processBeginHost(info){
	if(typeof info=="undefined" || info==null) info = Message.DataLoading;
	var dlg = $.dialog.tips(info,1800,'loading.gif',function(){ });
	dlg.DOM.wrap.css("top","45%");
	$("#bg-frame").remove();
	dlg.DOM.inner.append('<iframe id="bg-frame" class="bg-frame" frameborder="0" src="about:blank"></iframe>');
}
// 处理结束后提示信息框
function processEnd(info){
	if(typeof info=="undefined" || info==null) info = Message.DataLoaded;
	var dlg = $.dialog.tips(info,2,'succ.png',function(){ });
	dlg.DOM.wrap.css("top","40%");
	$("#bg-frame").remove();
	dlg.DOM.inner.append('<iframe id="bg-frame" class="bg-frame" frameborder="0" src="about:blank"></iframe>');
}
function processEndHost(info){
	if(typeof info=="undefined" || info==null) info = Message.DataLoaded;
	var dlg = $.dialog.tips(info,1,'succ.png',function(){ });
	dlg.DOM.wrap.css("top","40%");
	$("#bg-frame").remove();
	dlg.DOM.inner.append('<iframe id="bg-frame" class="bg-frame" frameborder="0" src="about:blank"></iframe>');
}
// 处理失败后提示信息框
function processError(info){
	if(typeof info=="undefined" || info==null) info = Message.ServerError;
	var dlg = $.dialog.tips(info,2,'face-sad.png',function(){ });
	dlg.DOM.wrap.css("top","40%");
	$("#bg-frame").remove();
	dlg.DOM.inner.append('<iframe id="bg-frame" class="bg-frame" frameborder="0" src="about:blank"></iframe>');
}
function processoMapError(info){
	if(typeof info=="undefined" || info==null) info = Message.MapMetaNull;
	var dlg = $.dialog.tips(info,1,'face-sad.png',function(){ });
	dlg.DOM.wrap.css("top","45%");
	$("#bg-frame").remove();
	dlg.DOM.inner.append('<iframe id="bg-frame" class="bg-frame" frameborder="0" src="about:blank"></iframe>');
	dlg.DOM.close.blur();
}
/************************** 数据操作按钮显示框 *********************
 * 依赖js-lib：jquery.js、jquery-lhgdialog
 * */
function detailBtn(id,info){
	var dlg = $.dialog({
			id:id,width:300,
		 	title:Message.ExportDetail,
		 	min:false,max:false,resize:false,drag:true,
		    content: info
	 });
	$("#bg-frame").remove();
	dlg.DOM.inner.append('<iframe id="bg-frame" class="bg-frame" frameborder="0" src="about:blank"></iframe>');
	dlg.DOM.close.blur();
	 return dlg;
}
// 词典类型转换中文
function parseDictype(dictypeAarry,type){
	var rv = type;
	$.each(dictypeAarry, function(i, e){
		  if(e.code==type) {
			  rv = e.name;
			  return false;
		  }
		});
	return rv;
}
// 转换为""
function parseEmpty(str){
	if(typeof(str)=="undefined" ||str=="undefined" || str==null || str=="null" || str==NaN || str=="NaN"){
		str = "";
	}
	return str;
}
function parseFileName(name){
	var i = name.lastIndexOf(".");
	return name.substring(0,i);
}
function parseTaskStatus(code){	
	var rv = code;
	var codes =["NOPROCESS","PROCESSING", "PROCESSED", "PROCESSFAILED"];
	var zhs =["未处理","处理中", "已完成", "失败"];
	$.each(codes, function(i, v){
		  if(v==code) {
			  rv = zhs[i];
			  return false;
		  }
		});
	return rv;
}	
function parseDateStr(d){
	var ds = d.split(":");
	return ds[0]+":"+ds[1];
}
// str 日期字符 et： 2010-10-31
// type=0时，返回 2010-10-31 00:00:00  当天开始时间
// type=1时，返回 2010-11-01 23:59:59  下一天开始时间
function getUserDate(str,type){
	if($.trim(str)=="")return "";
	if(type==0){
		return str + " 00:00:00";
	}
	if(type==1){
		str = str+" 23:59:59";
		var dt  = new Date(Date.parse(str.replace(/-/g,"/")));  
		var ndt = new Date(dt.valueOf());
		return ndt.getDateString("-");
	}
}
function showDialog(obj){
	var dialog = $(".index-dialog");
	if(obj.title == null || obj.title == "undefined"){
		obj.title = "";
	}
	if(obj.disable == null || obj.enable == "undefined"){
		obj.disable = true;
	}
	$(".index-dialog-title-text").text(obj.title);
	if(obj.width == null || obj.width == "undefined"){
		obj.width = 200;
	}
	if(obj.height == null || obj.height == "undefined"){
		obj.height = 200;
	}
	dialog.width(obj.width);
	dialog.height(obj.height);
	var top,left;
	var winWidth = document.documentElement.clientWidth || document.body.clientWidth;
	var winHeight = document.documentElement.clientHeight || document.body.clientHeight;
	if(obj.top == null || obj.top == "undefined"){
		top = (winHeight - dialog.height())/2;
	}else{
		top = obj.top;
	}
	if(obj.left == null || obj.left == "undefined"){
		left = (winWidth - dialog.width())/2;
	}else{
		left = obj.left;
	}
	if(obj.contents == null || obj.contents == "undefined"){
		obj.contents = "";
	}
	dialog.css("top",top+"px");
	dialog.css("left",left+"px");
	$(".index-dialog-content").height(dialog.height() - $(".index-dialog-title").height());
	$(".index-dialog-content").empty();
	$(".index-dialog-content").append(obj.contents);
	$(".index-dialog-close").unbind("click");
	$(".index-dialog-close").click(function(){
		closeDialog(function(){});
	});
	if(obj.disable){
		$(".index-dialog-cover").show();
	}
	dialog.show();
}
function closeDialog(init){
	$(".index-dialog-cover").hide();
	$(".index-dialog").hide();
	$(".index-dialog-title-text").empty();
	$(".index-dialog-content").empty();
	if(typeof init === "function"){
        init.call();
    }
	$("input").removeAttr("disabled");
	$("select").removeAttr("disabled");
}
function clearTimer(){
	if(timer != null){
		window.clearInterval(timer);
	}
}
function teacherChoice(callback){
	$(".index-dialog-cover",parent.parent.document).show();
	$(".tearcher-choice-dialog",parent.parent.document).show();
	if(typeof callback === "function"){
		callback.call();
    }
	$(".teacher-choice-close",parent.parent.document).unbind("click");
	$(".teacher-choice-close",parent.parent.document).click(function(){
		$(".tearcher-choice-dialog",parent.parent.document).hide();
		$(".index-dialog-cover",parent.parent.document).hide();
	});
}
function teacherChoice1(callback){
	$(".index-dialog-cover",parent.parent.parent.document).show();
	$(".tearcher-choice-dialog",parent.parent.parent.document).show();
	if(typeof callback === "function"){
		callback.call();
    }
	$(".teacher-choice-close",parent.parent.parent.document).unbind("click");
	$(".teacher-choice-close",parent.parent.parent.document).click(function(){
		$(".tearcher-choice-dialog",parent.parent.parent.document).hide();
		$(".index-dialog-cover",parent.parent.parent.document).hide();
	});
}
function leadingDialog(callback){
	$(".index-dialog-cover",parent.parent.document).show();
	$(".leading-dialog",parent.parent.document).show();
	if(typeof callback === "function"){
		callback.call();
    }
	$("#dialog-close",parent.parent.document).unbind("click");
	$("#dialog-close",parent.parent.document).click(function(){
		$(".leading-dialog",parent.parent.document).hide();
		$(".index-dialog-cover",parent.parent.document).hide();
	});
}
function studentChoice(callback){
	$(".index-dialog-cover",parent.parent.document).show();
	$(".student-choice-dialog",parent.parent.document).show();
	if(typeof callback === "function"){
		callback.call();
    }
	$(".student-choice-close",parent.parent.document).unbind("click");
	$(".student-choice-close",parent.parent.document).click(function(){
		$(".student-choice-dialog",parent.parent.document).hide();
		$(".index-dialog-cover",parent.parent.document).hide();
	});
}
function userChoice(obj,callback){
	var dialog = $(".index-dialog",parent.parent.document);
	$(".index-dialog-title-text",parent.parent.document).text(obj.title);
	if(obj.width == null || obj.width == "undefined"){
		obj.width = 200;
	}
	if(obj.height == null || obj.height == "undefined"){
		obj.height = 200;
	}
	dialog.width(obj.width);
	dialog.height(obj.height);
	var top,left;
	var winWidth = parent.parent.document.documentElement.clientWidth || parent.parent.document.body.clientWidth;
	var winHeight = parent.parent.document.documentElement.clientHeight || parent.parent.document.body.clientHeight;
	if(obj.top == null || obj.top == "undefined"){
		top = (winHeight - dialog.height())/2;
	}else{
		top = obj.top;
	}
	if(obj.left == null || obj.left == "undefined"){
		left = (winWidth - dialog.width())/2;
	}else{
		left = obj.left;
	}
	if(obj.contents == null || obj.contents == "undefined"){
		obj.contents = "";
	}
	dialog.css("top",top+"px");
	dialog.css("left",left+"px");
	$("#index-dialog-content",parent.parent.document).height(dialog.height() - $(".index-dialog-title",parent.parent.document).height());
	$("#index-dialog-content",parent.parent.document).empty();
	$("#index-dialog-content",parent.parent.document).append(obj.contents);
	$(".index-dialog-cover",parent.parent.document).show();
	dialog.show();
	if(typeof callback === "function"){
		callback.call();
    }
	$(".index-dialog-close",parent.parent.document).unbind("click");
	$(".index-dialog-close",parent.parent.document).click(function(){
		$(".index-dialog",parent.parent.document).hide();
		$(".index-dialog-cover",parent.parent.document).hide();
	});
}
function hideClassChoice(){
	$(".dialog-display-btnshow").show();
	$(".dialog-display-btnhide").hide();
	$(".teacher-choice-classdia").animate({right:"-110px"});
}

function subStr(str,length){
	if(str.length > length){
		str = str.substring(0,length-1) + "...";
	}
	return str;
}